﻿/*
 * 作者：刘李
 * 功能描述：套管类型
 * 时间：2018-01-20
 * 修改人：
 * 修改时间：
 *
 */

using DataAccess;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entity;


namespace DataBusiness
{
    public class DrillCombBLL
    {

        public static DataSet GetDrillComb(string WellNo)
        {
            //string sSql = "select WellNo, DrillingSequence, HoleSize, HoleSection_start, HoleSection_end, CombID "+
            //                "from tb_DrillCombination where WellNo = '"+WellNo+"'";

            string sSql = "select * from tb_DrillCombination where WellNo = '" + WellNo + "'";

            return SqlHelper.QuerySql(sSql);
        }

        public static DataSet GetDrillType()
        {
            string sSql = "select CombID, Name, OutsideDiameter, ToolsLength from tb_DrillType";
            //string sSql = "select * from tb_DrillType";

            return SqlHelper.QuerySql(sSql);
        }

        /// <summary>
        /// 插入套管组合数据
        /// </summary>
        /// <param name="t">单行数据</param>
        /// <param name="titles">表的标题</param>
        /// <returns>返回影响的行数</returns>
        public static int InsertDrillType(tb_DrillModel.TypeModel t, List<string> titles)
        {
            string sSql = "";

            sSql += "insert into tb_DrillCombination (";

            for (int i = 0; i < titles.Count; i++)
            {
                if (i != titles.Count - 1)
                {
                    sSql += (titles[i] + ",");
                }
                else
                {
                    sSql += (titles[i] + ") values ('");
                }
            }
            sSql += (t.WellNo + "','");
            sSql += (t.DrillingSequence + "','");
            sSql += (t.HoleSize + "','");
            sSql += (t.HoleSection_start + "','");
            sSql += (t.HoleSection_end + "','");
            sSql += (t.CombID + "','");
            sSql += (t.UserID + "','");
            sSql += (t.InputDate + "')");

            return SqlHelper.ExeSql(sSql);
        }

        /// <summary>
        /// 插入套管工具数据
        /// </summary>
        /// <param name="t">单行数据</param>
        /// <param name="titles">表的标题</param>
        /// <returns>返回影响的行数</returns>
        public static int InsertDrillComb(tb_DrillModel.CombModel t, List<string> titles)
        {
            string sSql = "";

            sSql += "insert into tb_DrillType (";

            for (int i = 0; i < titles.Count; i++)
            {
                if (i != titles.Count - 1)
                {
                    sSql += (titles[i] + ",");
                }
                else
                {
                    sSql += (titles[i] + ") values ('");
                }
            }
            sSql += (t.CombID + "','");
            sSql += (t.Name + "','");
            sSql += (t.OutsideDiameter + "','");
            sSql += (t.ToolsLength + "')");

            return SqlHelper.ExeSql(sSql);
        }

        public static int DeleteDrillType(string CombID)
        {
            string sSql = string.Format("delete from tb_DrillCombination where CombID='{0}'", CombID);
            return SqlHelper.ExeSql(sSql);
        }

        public static int DeleteDrillComb(string CombID)
        {
            string sSql = string.Format("delete from tb_DrillType where CombID='{0}'", CombID);
            return SqlHelper.ExeSql(sSql);
        }

    }
}
